package tcards.android;

import models.Status;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

public class UnitPage extends LinearLayout {
	public UnitPage(Context context) {
		this(context, null, 0);
	}

	public UnitPage(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public UnitPage(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		LayoutInflater li = LayoutInflater.from(context);
		addView(li.inflate(R.layout.unit_page, this, false));
	}
	
	public UnitField getField(int index) {
		return findField(Status.values()[index]);
	}
	
	public int getFieldCount() {
		return 6;
	}
	
	public UnitField findField(Status status) {
		switch (status) {
		case Available:
			return (UnitField) findViewById(R.id.available);
		case Assigned:
			return (UnitField) findViewById(R.id.assigned);
		case OSRest:
			return (UnitField) findViewById(R.id.osRest);
		case OSMechPers:
			return (UnitField) findViewById(R.id.osMechPers);
		default:
			throw new RuntimeException("No field associated with Status value: " + status.toString());
		}
	}
}